var objId =  getQueryString("objId");
var $;
layui.config({
	base : "js/"
}).use(['form','layer','jquery'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage;
		$ = layui.jquery;

	//根据出货单ID获取当前出货单的回收桶数
	getRecycleBucketSum();
	function getRecycleBucketSum()
	{
		
		$.ajax({
			        url: API_URL_HEAD+"outPutBills/getRecycleBucketNum/"+objId,
			        type: 'GET',
			        async: false,
//			        data: JSON.stringify(dto),
			        contentType: 'application/json; charset=utf-8',
			        dataType: 'json',
			        success: function (data) {
			        	var vo = data.data;
			        	if(data.code == 0)
			        	{
			        		$(".recycleBucketSum").val(vo);
			        	}
			        }
			  });
	}
	
    $("body").on("click",".validateCollectData",function(){  //检测数据
			//_this.parents("tr").remove();
			console.log(JSON.stringify(excelJson));
			var dto = 
			{
				"id":objId,
				"collectData":JSON.stringify(excelJson)
			}
			$.ajax({
			        url: API_URL_HEAD+"outPutBills/validateCollectData",
			        type: 'POST',
			        async: false,
			        data: JSON.stringify(dto),
			        contentType: 'application/json; charset=utf-8',
			        dataType: 'json',
			        success: function (data) {
			        	var vo = data.data;
						if(vo.flag)
						{
							layer.msg('检测成功！', {icon: 1}); 
							
						}else
						{
							$(".auditRemark").val(vo.errorMessage);
							layer.msg('数据不匹配！', {icon: 0}); 
						}
						
			        }
			  });
	})
 	form.on("submit(agree)",function(data){
 		var dto = 
 		{
 			"status":3,
 			"auditStatus":2,
 			"id":objId,
 			"recycleBucketSum":$(".recycleBucketSum").val(),
 			"auditRemark":$(".auditRemark").val()
 		}
 		$.ajax({
			        url: API_URL_HEAD+"outPutBills/updateOutPutBillsAuditStatus",
			        type: 'post',
			        contentType: 'application/json; charset=utf-8',
			        data: JSON.stringify(dto),
			        dataType: 'json',
			        success: function (data) {
			        	if(data.code == 0){
		               //刷新父页面
			 			parent.location.reload();
	            		}
			        }
			   });
 		return false;
 	})
	
})

//格式化时间
function formatTime(_time){
    var year = _time.getFullYear();
    var month = _time.getMonth()+1<10 ? "0"+(_time.getMonth()+1) : _time.getMonth()+1;
    var day = _time.getDate()<10 ? "0"+_time.getDate() : _time.getDate();
    var hour = _time.getHours()<10 ? "0"+_time.getHours() : _time.getHours();
    var minute = _time.getMinutes()<10 ? "0"+_time.getMinutes() : _time.getMinutes();
    return year+"-"+month+"-"+day+" "+hour+":"+minute;
}

//获取url中的参数
function getQueryString(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); // 匹配目标参数
  var result = window.location.search.substr(1).match(reg); // 对querystring匹配目标参数
  if (result != null) {
    return decodeURIComponent(result[2]);
  } else {
    return null;
  }
}